package com.xcw.jac;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class GetRequestExample {

    public static void main(String[] args) throws Exception {
        String url = "https://stabilityai-stable-diffusion.hf.space/queue/join";

        try {
            URL requestUrl = new URL(url);
            HttpURLConnection connection = (HttpURLConnection) requestUrl.openConnection();
            connection.setRequestMethod("GET");

            int responseCode = connection.getResponseCode();
            String responseBody = readResponse(connection);

            System.out.println("Status code: " + responseCode);
            System.out.println("Response body: " + responseBody);
        } catch (IOException e) {
            throw new Exception("Failed to send GET request", e);
        }
    }

    private static String readResponse(HttpURLConnection connection) throws IOException {
        StringBuilder response = new StringBuilder();
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
            String line;
            while ((line = reader.readLine()) != null) {
                response.append(line);
            }
        }
        return response.toString();
    }
}